package com.cyw.common.utils;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class SnowFlakeUtils {
    private static SnowFlake INSTANCE;

    @Value("${dataCenterId:0}")
    private Long dataCenterId;

    @Value("${machineId:0}")
    private Long machineId;

    @PostConstruct
    public void init() {
        INSTANCE = new SnowFlake(dataCenterId, machineId);
    }

    public static Long nextId() {
        return INSTANCE.nextId();
    }
}